﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using Com.CMS263.PO;
namespace Com.CMS263.DAO
{
   public class ProductTypeDAO
    {
       
       public ProductTypeDAO()
       { 
        
       }
       public void AddProductType(ProductType pt)
       {
           DBHelper.TransSaveOrUpdate(pt);
       }

       public IList<ProductType> GetAllType()
       {
           ISession session = DBHelper.GetISession;
           return session.CreateQuery("from ProductType  order by orderID desc").List<ProductType>();
       }
       public bool Modify(ProductType pt)
       {
           try
           {
               DBHelper.TransUpdate(pt);
               return true;
           }
           catch 
           {

               return false;
           }
       }
       public ProductType GetTypeById(int id)
       {
           return DBHelper.ExecuteHQL("from ProductType where id =" + id).List<ProductType>().First();
       }
       public bool DeleteById(int id)
       {
           try
           {
               DBHelper.ExecuteHQL("update ProductType set isShow = 0 where id=" + id).ExecuteUpdate();
               return true;
           }
           catch
           {

               return false;
           }
       }

       public IList<ProductType> GetShowType(int num)
       {
           return DBHelper.ExecuteHQL("from ProductType where isShow=1 order by orderID desc").SetFirstResult(0).SetMaxResults(num).List<ProductType>();
       }
    }
}
